//SUMMARY:  This do files provides replication of county-level findings for Ballard-Rosa, Jensen & Scheve (2021)

//Set directory
cd "C:\Users\cambr\Dropbox\US Authoritarianism\Paper\ISQ\ISQ replication materials\Data"
global output "C:\Users\cambr\Dropbox\US Authoritarianism\Paper\ISQ\ISQ replication materials\Output" 

clear all
set more off

use "Avg racial income by county (2016).dta", replace

* China shock data
merge 1:1 countyid2010 using "cty2010_czone_shock.dta"
drop if _merge == 2
drop _merge

* Foreign born data
merge m:1 countyid2010 using "foreignborn.dta"
drop if _merge==2
drop _merge

* Ethnicity data
merge m:1 countyid2010 using "ethnicity.dta"  
drop if _merge==2
drop _merge

//Create variables
gen white_black_inc = avgInc_whites_nh / avgInc_blacks_nh
gen white_hisp_inc = avgInc_whites_nh / avgInc_allHispanic

g shock_v2=d_czone_imp_exp_usch_1991_2007
lab var shock_v2 "$\Delta$ IP (91-07)"
lab var fb_pct2015 "% Foreign Born"
lab var fb_chg_20002015 "$\Delta$ % Foreign Born"
label var share_white "% White"

//TABLE 3: Trade shock and county average income (by race)
reg white_chg0716 shock_v2, robust
outreg2 using "$output/income_by_race.xls", replace tex(fra) ctitle(\Delta White inc.) nocons bdec(3) label
reg white_chg0716 shock_v2 fb_pct2015 fb_chg_20002015 share_white , robust
outreg2 using "$output/income_by_race.xls", append tex(fra) ctitle(\Delta White inc.) nocons bdec(3) label 
reg black_chg0716 shock_v2, robust
outreg2 using "$output/income_by_race.xls", append tex(fra) ctitle(\Delta Black inc.) nocons bdec(3) label 
reg black_chg0716 shock_v2 fb_pct2015 fb_chg_20002015 share_white , robust
outreg2 using "$output/income_by_race.xls", append tex(fra) ctitle(\Delta Black inc.) nocons bdec(3) label 
reg white_black_inc shock_v2, robust
outreg2 using "$output/income_by_race.xls", append tex(fra) ctitle(W/B inc.) nocons bdec(3) label 
reg white_black_inc shock_v2 fb_pct2015 fb_chg_20002015 share_white , robust
outreg2 using "$output/income_by_race.xls", append tex(fra) ctitle(W/B inc.) nocons bdec(3) label 
